/***2023-02-07 迷途小羔羊
 * 用于编写角色行走时，记录的行走信息的数据结构类
 * 
*/
namespace ghost{
    export enum MoveResult
    {
        NONE=0,
        /**当前移动碰到障碍，无法通行，此情况会改变通行方向，但是坐标不会有变化，默认为BARRIER状态*/
        BARRIER=1,
        /**当前移动存在阻挡单位无法，无法通行*/
        HIT=2,
        /**当前移动存在通行方向*/
        PASS=4,
        /**当前移动碰到墙壁，会改变方向，进行贴墙移动*/
        WALL=8        
        
    }
    
    export class MoveState{
        
        
        public _fromX:number;
        public _fromY:number;
        public _toX:number;
        public _toY:number;        
        public _fromCol:number;
        public _toCol:number;
        public _fromRow:number;
        public _toRow:number;
        public result:MoveResult;
        public _role:Role;
        public _angle:number;
        public _speed:number;
        /**当撞墙后，产生的偏转角，进行偏转后，能通行result结果为WALL*/
        public deflectionAngle:number;
        constructor(r:Role)
        {
            this._role = r;
        }
        /**设置位移信息
         * @param r 角色
         * @param agl 行走角度
         * @param speed 移动该速度
         * @param posGridW 移动格子宽度
         * @param posGridH 移动格子高度
        */
        public setData(r:Role,agl:number,speed:number,posGridW:number,posGridH:number):void
        {
            let s= this;
            s._angle = agl;
            s._speed = speed;
            s._fromCol = r.col;
            s._fromRow = r.row;
            s._fromX = r.absX;
            s._fromY = r.absY;            
            if(speed == 0)
            {
                s._toX = s._fromX;
                s._toY = s._fromY;
                s._toCol = s._fromCol;
                s._toRow = s._fromRow;
            }
            else
            {
                s._toX = s._fromX + ((agl == MathConst.HALF_PI || agl == -MathConst.HALF_PI)?0:Math.cos(agl) * speed);
                s._toY = s._fromY + ((agl == Math.PI || agl == -Math.PI)?0:Math.sin(agl) * speed);
                s._toCol = Math.floor(s._toX / posGridW);
                s._toRow = Math.floor(s._toY / posGridH);
            }            
            s.result = MoveResult.NONE;
        }        
        /**设定X方向遭遇障碍*/
        public barrierX():void
        {
            let s = this;
            s._toX = s._fromX;
        }
        /**设定Y方向遭遇障碍*/
        public barrierY():void
        {
            let s = this;
            s._toY = s._fromY;
        }
        /**此次移动是否格子定位改变*/
        public isPosChange():boolean
        {
            let s= this;
            return s._fromCol != s._toCol || s._fromRow != s._toRow;
        }
        /**此次移动是否格子定位列改变*/
        public isColChange():boolean
        {
            let s= this;
            return s._fromCol != s._toCol;
        }
        /**此次移动是否格子定位行改变*/
        public isRowChange():boolean
        {
            let s= this;
            return s._fromRow != s._toRow;
        }
        /**此次移动是否xy坐标有改变*/
        public isXYChange():boolean
        {
            let s= this;
            return s._fromX != s._toX || s._fromY != s._toY;
        }
        /**此次移动是否xy坐标其中之一没有改变*/
        public isXOrYNotChange():boolean
        {
            let s= this;
            return s._fromX == s._toX || s._fromY == s._toY;
        }
        /**此次移动是否x坐标有改变*/
        public isXChange():boolean
        {
            let s= this;
            return s._fromX != s._toX;
        }
        /**此次移动是否y坐标有改变*/
        public isYChange():boolean
        {
            let s= this;
            return s._fromY != s._toY;
        }
        public distanceX():number
        {
            let s = this;
            return s._fromX > s._toX?s._fromX - s._toX:s._toX - s._fromX;
        }
        public distanceY():number
        {
            let s = this;
            return s._fromY > s._toY?s._fromY - s._toY:s._toY - s._fromY;
        }
    }
}